package com.smart.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.common.PageInfo;
import com.smart.model.dtomapper.JiansheProjectDtoMapper;
import com.smart.model.domain.JiansheProjectDO;
import com.smart.mapper.JiansheProjectMapper;
import com.smart.model.request.JiansheProjectRequest;
import com.smart.service.JiansheProjectService;
import com.smart.model.convert.JiansheProjectConvert;
import com.smart.model.vo.JiansheProjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhanghong
 */
@Service
public class JiansheProjectServiceImpl extends ServiceImpl<JiansheProjectMapper, JiansheProjectDO> implements JiansheProjectService {
    @Autowired
    private JiansheProjectMapper jiansheProjectMapper;

    @Override
    public JiansheProjectVO getByKey(long id) {
        JiansheProjectDO jiansheProjectDO = getById(id);
        JiansheProjectVO jiansheProjectVO = JiansheProjectDtoMapper.INSTANCE.do2VO(jiansheProjectDO);
        return jiansheProjectVO;
    }

    @Override
    public PageInfo<JiansheProjectVO> pageQuery(JiansheProjectRequest request) {
        long count = jiansheProjectMapper.pageCount(request);
        List<JiansheProjectDO> list = jiansheProjectMapper.pageQuery(request, request.getPageSize(), request.fetchOffSet());
        List<JiansheProjectVO> jiansheProjectVOList = JiansheProjectConvert.buildJiansheProjectVoList(list);
        return new PageInfo(request.getPageNum(), request.getPageSize(), jiansheProjectVOList, count);
    }

    @Override
    public List<JiansheProjectVO> listQuery(JiansheProjectRequest request) {
        List<JiansheProjectDO> list = list();
        List<JiansheProjectVO> jiansheProjectVOS = JiansheProjectConvert.buildJiansheProjectVoList(list);
        return jiansheProjectVOS;
    }

    @Override
    public Boolean add(JiansheProjectRequest request) {
        JiansheProjectDO jiansheProjectDO = JiansheProjectDtoMapper.INSTANCE.request2DO(request);
        save(jiansheProjectDO);
        return true;
    }

    @Override
    public Boolean updateByKey(JiansheProjectRequest request) {
        JiansheProjectDO jiansheProjectDO = JiansheProjectDtoMapper.INSTANCE.request2DO(request);
        save(jiansheProjectDO);
        return true;
    }

    @Override
    public Boolean deleteByKey(long id) {
        jiansheProjectMapper.deleteDOById(id);
        return true;
    }
}
